@extends('backend/layouts/default')
@section('title')
Danh sách  thông báo lỗi
@stop
@section('content')

<h3>
    <span class="glyphicon glyphicon-pencil"></span> Danh sách thông báo lỗi

</h3>
<div class="box">
    <div class="box-header">
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <div class="row">
            <div class="col-ld-2 col-md-3 col-sm-3">
                <ul class="nav nav-pills nav-stacked">

                </ul>
            </div>
            <div class="col-ld-10 col-md-9 col-sm-9">
                <form method="get" action="" autocomplete="off" role="form" class="form-inline">
                    <input type="hidden" name="_token" value="{{ csrf_token() }}"/>

                    <div class="form-group">
                        <?= Form::select('type', array('default' => 'Thể loại', 'hoi-dap' => 'Câu hỏi', 'bai-giang' => 'Bài giảng', 'tu-dien' => 'Từ điển', 'hop-am' => 'Hợp âm'), $data['appends']['type'], array('class' => 'form-control')); ?>
                    </div>
                    <div class="form-group">
                        <?= Form::select('status', array('default' => 'trạng thái') + array('new' => 'Mới tạo', 'insolve' => 'Đang xử lý', 'wait' => 'Chờ xử lý', 'solved' => 'Đã xử lý'), $data['appends']['status'], array('class' => 'form-control')); ?>
                    </div>
                    <input type="submit" class="btn btn-default btn-info" name="search" value="Tìm"/>
                </form>
                <hr/>
                <table style=" table-layout: fixed;
                       word-wrap: break-word;" class="table table-hover table-bordered">
                    <thead>
                        <tr>
                            <th width="50"></th>
                            <th width='150'>Nội dung bị báo sai phạm</th>
                            <th width='300'>Nội dung thông báo</th>
                            <th width="150">Người tạo</th>
                            <th width="100">Loại</th>
                            <th width ='100'>Trạng thái</th>
                            <th width="150">Ngày tạo</th>
                            <th width="100">Tác vụ</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data['errors'] as $error)
                        <tr  class="error">
                            <td>{{$error->id}}</td>
                            <td><a href="{{$error->link}}"> {{$error->title}}</a>
                            </td>
                            <td>
                                <?= strlen($error->content) < 100 ? $error->content : substr($error->content, 0, 100) . '..........' ?> 
                            </td>
                            <td><a href="{{route('thanh-vien-ct',array('id'=>$error->user_id,'slug'=>Str::slug($error->username)))}}">{{$error->username}}</a></td>
                            <td><?php
                                switch ($error->type) {
                                    case 'hoi-dap':
                                        echo "Hỏi đáp";
                                        break;
                                    case 'hop-am':
                                        echo "Hợp âm";
                                        break;
                                    case 'bai-giang':
                                        echo "Bài giảng";
                                    case 'tu-dien':
                                        echo "Từ điển";
                                        break;
                                }
                                ?></td>
                            <td>
                                <?php
                                switch ($error->status) {
                                    case 'new':
                                        echo "Mới";
                                        break;
                                    case 'insolve':
                                        echo "Đang xử lý";
                                        break;
                                    case 'wait':
                                        echo "Chờ xử lý";
                                        break;
                                    case 'solved':
                                        echo "Đã xử lý";
                                        break;
                                }
                                ?>

                            </td>
                            <td>{{$error->created_at}}</td>
                            <td> 
                                <a href="{{ route('error\delete', $error->id) }}" class="btn btn-mini btn-danger">@lang('button.delete')</a>
                                <a href="" class="clik-resolve btn btn-mini btn-default" error_id="{{$error->id}}" data-toggle="modal" data-target="#content_error{{$error->id}}">xử lý</a>
                                <!--                             @include('backend/Errors/show/detail_error')-->
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
                @include('backend/Errors/show/detail_error')
                <?= $data['errors']->links(); ?>
            </div>
        </div>
    </div>
</div>
<div class="add-detail-error">

</div>
<script>
    $(document).ready(function () {

        $(document).on('mouseenter', '.clik-resolve', function (e) {
            show_Detail_Error($(this).attr('error_id'));
            e.preventDefault();
        });
    });
    function show_Detail_Error(id) {
        $.ajax({
            type: 'POST',
            url: '<?= route('show-detail-error') ?>?error_id=' + id,
            dataType: 'json',
        }).done(function (data) {

            $('.add-detail-error').html(data);

            // location.hash = '?page_answer='
        }).fail(function () {
            alert('Posts could not be loaded.');
        });
    }
    function show_confirm(obj) {
        var r = confirm("Bạn có thực sự muốn xóa?");
        if (r == true)
            window.location = obj.attr('href');
    }
    $('a.btn-danger').click(function (event) {
        event.preventDefault();
        show_confirm($(this));
    });

</script>

@stop